package openase.audiosearch.comm.request.decoder.factory;

import openase.audiosearch.comm.request.Request;
import openase.audiosearch.comm.request.RequestType;
import openase.audiosearch.comm.request.decoder.AudioRegistrationRequestDecoder;
import openase.audiosearch.comm.request.decoder.AudioSearchRequestDecoder;
import openase.audiosearch.comm.request.decoder.DummyRequestDecoder;
import openase.audiosearch.comm.request.decoder.RequestDecoder;

public class RequestDecoderFactory {

	private RequestDecoderFactory() {
	}

	@SuppressWarnings("unchecked")
	public static <T extends Request> RequestDecoder<T> getDecoder(RequestType type) {
		if (type == null) {
			return (RequestDecoder<T>) new DummyRequestDecoder();
		}

		switch (type) {
		case REGISTER:
			return (RequestDecoder<T>) new AudioRegistrationRequestDecoder();
		case SEARCH:
			return (RequestDecoder<T>) new AudioSearchRequestDecoder();
		}

		return (RequestDecoder<T>) new DummyRequestDecoder();
	}

}
